package interview;

public class interview_05_03 {
    public int reverseBits(int num) {
        int[][] dp=new int[33][2];
        int[] number=new int[33];
        int len=1;
        while(num!=0){
            number[len-1]=num&1;
            len++;
            num=num>>>1;
        }
        dp[0][0]=1;
        dp[0][1]=1;
        if(number[0]==0) dp[0][0]=0;
        int max=0;
        for(int i=1;i<32;++i){
            if(number[i]==0){
                dp[i][0]=0;
                dp[i][1]=dp[i-1][0]+1;
            }else{
                dp[i][0]=dp[i-1][0]+1;
                dp[i][1]=Math.max(dp[i-1][0],dp[i-1][1])+1;
            }
            max=Math.max(max,dp[i][0]);
            max=Math.max(max,dp[i][1]);
        }
        return max;
    }
}
